﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportView.aspx.cs" EnableEventValidation="false" MasterPageFile="~/Reports/Report.Master" Inherits="NPMonitor.Web.ReportView" %>
<%@ Register src="../UserControls/ReportControl.ascx" tagname="ReportControl" tagprefix="uc1" %>
<%@ Register src="../UserControls/ReportTimePicker.ascx" tagname="ReportTimePicker" tagprefix="uc2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<div id="divTopBar">
    <ul>
        <a href="ReportView.aspx?ReportType=Hourly" ><li id="Hourly">Hourly</li></a>
        <a href="ReportView.aspx?ReportType=Daily" ><li id="Daily" >Daily</li></a>
        <a href="ReportView.aspx?ReportType=Weekly" ><li id="Weekly">Weekly</li></a>
        <a href="ReportView.aspx?ReportType=Monthly" ><li id="Monthly">Monthly</li></a>
        <a href="ReportView.aspx?ReportType=Yearly" ><li id="Yearly">Yearly</li></a>
    </ul>
    <div class="clear">
    </div>
</div>
<div id="divSearchCondition">
    <br />
    <dl>
        <dd>
            <asp:HiddenField ID = "hfReportType" runat = "server" Value = "Daily" />
            <uc2:ReportTimePicker ID="rtpTimeSelector" runat="server" />
        </dd>
        <dd>
            <label>Job</label>
            <asp:DropDownList ID="ddlJob" runat="server" ></asp:DropDownList>
            <asp:RequiredFieldValidator ID="rfvJobName" runat="server" ForeColor="Red" ControlToValidate="ddlJob" Font-Italic="true"></asp:RequiredFieldValidator>
        </dd>
        <dd>
            <label>Scenario</label> 
            <asp:DropDownList ID="ddlSenario" runat="server"></asp:DropDownList>
            <asp:HiddenField ID="hfScenarioNO" runat="server" />
            <asp:CustomValidator ID="cvScenarioNO" runat="server" ValidateEmptyText="true" ForeColor="Red" Font-Italic="true" ControlToValidate="ddlSenario" ClientValidationFunction="CheckScenario"></asp:CustomValidator>
        </dd>
        <dd id="ddLocations">
            <label>Locations</label>
            <asp:CheckBoxList runat="server" RepeatDirection="Horizontal" RepeatColumns="5"  ID="chkLocation">
            </asp:CheckBoxList>
            <asp:TextBox ID="txtValidate" runat="server"></asp:TextBox>
        </dd>
        <dd>
             <label>&nbsp;</label>
             <asp:CustomValidator ID="cvLocation" ValidateEmptyText="true" runat="server"  ForeColor="red"
        ErrorMessage="Location must be selected" ControlToValidate="txtValidate" ClientValidationFunction="ValidateLocation"></asp:CustomValidator>
        </dd>
        <dd>
            <asp:Button ID="btnViewReport" runat="server" Text="View Report" CssClass="blueBTN" OnClick="btnViewReport_Click"  />
        </dd>
    </dl>
</div>
    
    <uc1:ReportControl ID="ucReport" runat="server" />

<script type="text/javascript">
    var ddlJob = $("#<%=ddlJob.ClientID %>");
    var ddlSenario = $("#<%=ddlSenario.ClientID %>");
    var hfdReportType = $("#<%=hfReportType.ClientID%>");
    var hfScenarioNO = $("#<%=hfScenarioNO.ClientID %>");
    var chkLocation = $("#<%=chkLocation.ClientID %>");
    var btnViewReport = $("#<%=btnViewReport.ClientID %>");
    var txtValidate = $("#<%=txtValidate.ClientID %>");
    var hiddenfield = hfdReportType.val();

    $(function () {
        $(txtValidate).css("display", "none");
        $("#" + hiddenfield + "").addClass("selected");
        var jobid = ddlJob.children("option[selected]").val();
        ddlJob.on("change", function () {
            InitScenarioList(ddlSenario, ddlJob.children("option[selected]").val());
            hfScenarioNO.val("");
        });
        ddlSenario.on("change", function () {
            hfScenarioNO.val(ddlSenario.children("option[selected]").val());
        });
        //if (jobid != "") {
        InitScenarioList(ddlSenario, jobid);
        ddlSenario.find("option[value='" + hfScenarioNO.val() + "']").attr("selected", "selected");
        //}

        if (typeof (ValidateTime) == "function") {
            $(btnViewReport).click(ValidateTime)
        }
    });

    function ValidateLocation(source, args) {
        var result = false;
        var ddLocations = $("#ddLocations");
        ddLocations.find("input[type=checkbox]").each(function (n, e) {
            if ($(e).attr("checked") == "checked") {
                result = true;
            }
        });
        args.IsValid = result;
    }

    //    function CheckScenario(source, args) {
    //        args.IsValid = false;
    //        var selectedOption = ddlSenario.children("option[selected]").val();
    //        if (selectedOption != null && selectedOption != selectString && selectedOption != "") {
    //            args.IsValid = true;
    //        }
    //    }
</script>
    
</asp:Content>